package com.xnyzc.lhy.order.service.impl.order;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xnyzc.lhy.common.penum.EOrderType;
import com.xnyzc.lhy.common.util.IDUtil;
import com.xnyzc.lhy.order.entity.param.order.OrderParam;
import com.xnyzc.lhy.order.entity.util.OrderUtil;
import com.xnyzc.lhy.order.entity.order.OaCOrderDeptOfficial;
import com.xnyzc.lhy.order.entity.order.OaDOrder;
import com.xnyzc.lhy.order.entity.gps.OaDVehicleGps;
import com.xnyzc.lhy.order.mapper.order.OaCOrderDeptOfficialMapper;
import com.xnyzc.lhy.order.service.order.IOaCOrderDeptOfficialService;
import com.xnyzc.lhy.order.service.order.IOaDOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 部门公务订单 服务实现类
 * </p>
 *
 * @author lhy@xnyzc.com
 * @since 2019-07-22
 */
@Service
public class OaCOrderDeptOfficialServiceImpl extends ServiceImpl<OaCOrderDeptOfficialMapper, OaCOrderDeptOfficial> implements IOaCOrderDeptOfficialService {

    @Autowired
    private IOaDOrderService oaDOrderService;

    @Autowired
    private OaCOrderDeptOfficialMapper deptOfficialMapper;

    @Override
    public boolean distributeOrderDeptOfficial(OaCOrderDeptOfficial deptOfficial, OrderParam oaDOrder, OaDVehicleGps vehicleGps) {
        String orderNo = OrderUtil.orderNo(EOrderType.BMGW);
        try {
            if (oaDOrderService.addOrder(vehicleGps, oaDOrder)) {
                //生成自费订单
                deptOfficial.setOrderNo(orderNo);

                //生成自费订单
                return this.updateById(deptOfficial);
            }
        } catch (Exception e) {
            return false;
        }
        return false;
    }

    @Override
    public String orderDeptOfficial(OaCOrderDeptOfficial deptOfficial) {
        String orderNo = OrderUtil.orderNo(EOrderType.BMGW);
        //生成自费订单
        deptOfficial.setOrderNo(orderNo);
        deptOfficial.setDeptOfficialId(IDUtil.nextId());
        //生成自费订单
        return this.save(deptOfficial) ? orderNo : "" ;

    }

}
